from bilibili_api import video, sync, Credential
from bs4 import BeautifulSoup
import datetime

# 创建了一个对应BV号的视频类，600条
# v = video.Video(bvid='BV1j4411W7F7')
# v = video.Video(bvid='BV1ex4y1N7sD')
# v = video.Video(bvid='BV1pg4y1b7dY')
v = video.Video(bvid='BV1fx411N7bU')
# 获取弹幕
# dms = sync(v.get_danmaku_xml(0))
# bs = BeautifulSoup(dms,'xml')
# dms = bs.find_all("d")
# dm_list = []
# for dm in dms:
#     dm_list.append(dm.get_text())
# print(len(dm_list))

# dms = sync(v.get_danmakus(0, datetime.date(2023, 3, 1)))
# for dm in dms:
#     print(dm)
# 获取特定月份存在历史弹幕的日期。
# print(sync(v.get_history_danmaku_index(0,datetime.date(2023, 3, 1))))

# 获取cid信息
# print("BV号",v.get_bvid())
# print("aid号",v.get_aid())

# 获取当前视频信息
# print(sync(v.get_info())['title'])
# 收藏点赞投币信息
# print(sync(v.get_stat()))
# 获得视频的标签
# tags = sync(v.get_tags())
# tags_text = []
# for tag in tags:
#     tags_text.append(tag['tag_name'])
# print(tags_text)
# 获得给视频充电的人
# chargers = ''
# try:
#     chargers = sync(v.get_chargers())
# except Exception as e:
#     print("UP不展示充电信息")
# finally:
#     if chargers['total_count'] == 0:
#         print('无人充电')
#     elif chargers['total_count']>0:
#         chargers_list = []
#         for charger in chargers['list']:
#             chargers_list.append(charger['uname'])
#         print(chargers_list)
#     else:
#         print('意外状况')

# 获取视频分P信息
# pages = sync(v.get_pages())
# if len(pages)==1:
#     print("只有一个分p:",pages[0]['part'])
# else:
#     page_list = {}
#     for page in pages:
#         page_list[page['page']] = page['part']
#     print(page_list)